<?php
/*
  $Id: $
*/

  require('include/application_top.php');

  $action = (isset($_GET['action']) ? $_GET['action'] : '');

  if ($action) {
    switch ($_GET['action']) {
      case 'save':
        db_update('configuration', array(
          'value'      => $_POST['value'],
          'updated_at' => 'now()'
        ), "id = '" . intval($_GET['id']) . "'");
        redirect(tep_href_link(FILENAME_CONFIGURATION, 'group_id=' . $_GET['group_id'] . '&id=' . intval($_GET['id'])));
        break;
    }
  }
  
  #$group = db_fetch("select * from configuration_group where id = '" . $_GET['group_id'] . "'");
  $group = db_fetch("select * from configuration_group where id = '1'");
  define('TITLE', $group['title']);
?>
<?php include 'include/header.php';?>
<?php include 'include/column_left.php';?>
    <div id="right">
      <table id="module_information" border="0" width="100%" cellspacing="0" cellpadding="0">
        <tr>
          <td><h2><?php echo $group['title'];?></h2></td>
        </tr>
      </table>
      <table id="module_table" border="0" width="100%" cellspacing="0" cellpadding="0">
        <tr>
          <td valign="top">
            <!-- listing -->
            <table id="module_listing" border="0" width="100%" cellspacing="0" cellpadding="0">
              <tr class="table_heading_row">
                <th align="left" class="table_heading left_th">标题</th>
                <th align="left" class="table_heading right_th">值</th>
              </tr>
<?php
  $configurations = db_fetch_all("select * from configuration where group_id = " . $group['id'] . " and status='visiable' order by sort_order desc");
  $query_numrows  = count($configurations);
  foreach ($configurations as $item) {
    if ((!isset($_GET['id']) && !isset($info)) || (isset($_GET['id']) && $_GET['id'] == $item['id'])) $info = $item;
?>
              <tr onclick="document.location.href='?id=<?php echo $item['id'];?>'"
                  onmouseover="this.className='table_row_mouse_over'"
<?php if (isset($info['id']) && $item['id'] == $info['id']) {?>
                  class="select_row"
                  onmouseout="this.className='select_row'"
<?php } else { ?>
                  onmouseout="this.className='table_row_mouse_out'"
<?php } ?>
              >
                <td><?php echo $item['title'];?></td>
                <td><?php echo $item['value'];?></td>
              </tr>
<?php }?>
            </table>
          </td>
          <!-- information -->
          <td id="item_information" class="information" width="30%" valign="top">
<?php
  switch ($action) {
    case 'edit':
?>
<h3>编辑设置</h3>
<form action="?action=save" method="post">
<input type="hidden" name="id" value="<?php echo $info['id'];?>" />
<fieldset><legend>值</legend><input type="text" name="value" value="<?php echo $info['value'];?>" /></fieldset>
<p><input type="submit" /> <input type="reset" /></p>
</form>
<?php
      break;
    default:
      if ($query_numrows) {
?>
<h3>设置信息</h3>
<div class="object_action">
<a href="?action=edit&id=<?php echo $info['id'];?>">编辑</a>
</div>
<h4><?php echo $info['title'];?></h4>
<?php echo $info['value'];?>
<?php
      }
      break;
  }
?>
          </td>
        </tr>
      </table>
    </div>
<?php include 'include/footer.php';?>
<?php require('include/application_bottom.php');?>
